Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: custom-metadata, exists, info methods #207

Merged
merged 1 commit into from
Aug 21, 2024
Merged

Conversation

fenos
Copy link
Contributor

@fenos fenos commented Jul 12, 2024

What kind of change does this PR introduce?

Feature

What is the new behavior?

Custom Metadata

Adds support for custom metadata on objects:

const res = await storage.from(bucketName).upload(uploadPath, file, {
        metadata: {
          custom: 'metadata',
          second: 'second',
          third: 'third',
        },
})

Exists / Info

added 2 new methods, exists and info

Info
fetches the information about this object

const {data: obj} = await storage.from(bucketName).info(uploadPath)

obj.id
obj.metadata

Exists
Check if a file exists

const {data: exists} = await storage.from(bucketName).exists(uploadPath)

console.log(exists) // true / false

Relates to supabase/storage#439

@fenos fenos force-pushed the feat/custom-metadata branch 3 times, most recently from 2f3d446 to 9b2da42 Compare July 16, 2024 09:44
src/packages/StorageFileApi.ts Outdated Show resolved Hide resolved
src/packages/StorageFileApi.ts Outdated Show resolved Hide resolved
@fenos fenos force-pushed the feat/custom-metadata branch 3 times, most recently from c67e610 to f85be2c Compare July 16, 2024 12:32
@fenos fenos force-pushed the feat/custom-metadata branch from f85be2c to cdd361e Compare July 17, 2024 09:54
@fenos fenos force-pushed the feat/custom-metadata branch from cdd361e to dbd5883 Compare July 17, 2024 09:59
@y4my4my4m
Copy link

y4my4my4m commented Aug 2, 2024

Is this merge waiting a certain release cycle?

For what it's worth, the code looks fine to me.
Cheers

@danvoyce
Copy link

danvoyce commented Aug 9, 2024

Hey folks, super eager to start using this.

Is this merge waiting a certain release cycle?

For what it's work, the code looks fine to me. Cheers

+1

Desperately need this feature 🙏

@bombillazo
Copy link
Contributor

Hey, yeah, we're also waiting on this feature for a while.

@adamski
Copy link

adamski commented Aug 15, 2024

Is there an estimated timescale for merging of this PR and subsequent release?

@logemann
Copy link

+1 for merging. This one is more important to me than a lot of stuff which got released in last launch weeks. Sometimes supabase team loses sight of the basic requirements still missing like this one...

@fenos
Copy link
Contributor Author

fenos commented Aug 19, 2024

Apologies for the delay guys, i'm aiming to have this merged this week.
The rollout has already started

@fenos fenos merged commit 716d679 into main Aug 21, 2024
1 check passed
@fenos fenos deleted the feat/custom-metadata branch August 21, 2024 09:11
@kiwicopple
Copy link
Member

🎉 This issue has been resolved in version 2.7.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@jan-tennert
Copy link

@fenos I'm confused about the implementation of the info method. The method uses the object/info/{bucketName}/{wildcard} route

const data = await get(this.fetch, `${this.url}/object/info/${_path}`, {
headers: this.headers,
})

which seems to be deprecated in the API docs and upon testing this release I get

StorageApiError: Object not found

errors.
The /object/info/public/{bucketName}/{wildcard} and object/info/authenticated/{bucketName}/{wildcard} routes seem to be working 🤔

@fenos
Copy link
Contributor Author

fenos commented Aug 22, 2024

Hey @danvoyce do you have RLS for selecting the object?

The route is probably marked as deprecated mistakingly, thanks for point that out

@jan-tennert
Copy link

jan-tennert commented Aug 22, 2024

@fenos, well the bucket is public and I'm using the service key. exists returns true for both public & private bucket files I tried. Currently trying to implement this for supabase-kt, but storage-js gives me the same error as shown above. This is the JS code I used:

import { StorageClient } from '@supabase/storage-js'

const STORAGE_URL = 'url'
const SERVICE_KEY = 'service key' //! service key, not anon key

const storageClient = new StorageClient(STORAGE_URL, {
  apikey: SERVICE_KEY,
  Authorization: `Bearer ${SERVICE_KEY}`,
})

const data = await storageClient.from("test").info("test.txt") //test is a public bucket
console.log(data.error) //StorageApiError: Object not found
console.log(data.data)
const exists = await storageClient.from("test").exists("test.txt")
console.log(exists.data) // true

@cipriancaba
Copy link

Is there a rollout plan for this in the main supabase-js package @kiwicopple ?

@fenos
Copy link
Contributor Author

fenos commented Aug 23, 2024

@cipriancaba yes, here is the PR

@danvoyce
Copy link

Hey @fenos you know when it's likely to be merged? I see it's been approved already 🤓

@danvoyce
Copy link

@fenos it's currently not possible to add new RLS policies to the objects table. Is there a way to allow users to modify the metadata somehow?

@apportunities
Copy link

Is there documentation on how to add metadata through TUS uploads?

The PR here indicates TUS is supported: supabase/storage#518

@khera
Copy link

khera commented Sep 1, 2024

🎉 This issue has been resolved in version 2.7.0 🎉

This is awesome, but neither the Guide nor the Javascript reference documentation mention this capability. Please, please, update the documentation when new features are added.

Thanks!

@icopp
Copy link

icopp commented Oct 4, 2024

Any documentation available for this yet?

@naimRahman08
Copy link

naimRahman08 commented Oct 9, 2024

I am also facing the same issue as @jan-tennert. For me its showing

StorageApiError: Bucket not found

although file is uploading correctly but info throws the above error

Also documentation would be great

@IstoraMandiri
Copy link

IstoraMandiri commented Oct 15, 2024

Is there documentation on how to add metadata through TUS uploads?

See https://github.com/supabase/storage/blob/689d255c82df0bde49c3786f5938c4a0d1933cf2/src/test/tus.test.ts#L98-L100

Or, using Uppy:

    new Uppy({
      // ...
      onBeforeFileAdded(file) {
        file.meta = {
          ...file.meta,
          bucketName: BUCKET,
          objectName: file.name,
          contentType: file.type,
          metadata: JSON.stringify({ test: "hello" }),
        };
        return file;
      },
    })
      .use(Tus, {
        // ...
        allowedMetaFields: ["bucketName", "objectName", "contentType", "cacheControl", "metadata"],
        // ...
      }),
  );

@apportunities
Copy link

apportunities commented Oct 25, 2024

I am also facing the same issue as @jan-tennert. For me its showing

StorageApiError: Bucket not found

although file is uploading correctly but info throws the above error

Also documentation would be great

Same issue on my end. I can fetch the file and download it, and I can call the exists method on it and it returns true. If I call the .info method, it returns StorageApiError: Bucket not found.

It works if I append either authenticated/ or public/ to the bucket name, e.g.:

let { data: info } = await supabase.storage
    .from("public/my-bucket")
    .info("my_photo.png");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.